package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.SettleAccountDate;
import com.prs.crm.service.sys.SettleAccountDateService;

public class SettleAccountDateAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private SettleAccountDate settleAccountDate;
	private SettleAccountDateService settleAccountDateService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public SettleAccountDate getSettleAccountDate() {
		return settleAccountDate;
	}
	public void setSettleAccountDate(SettleAccountDate settleAccountDate) {
		this.settleAccountDate = settleAccountDate;
	}
	public SettleAccountDateService getSettleAccountDateService() {
		return settleAccountDateService;
	}
	public void setSettleAccountDateService(
			SettleAccountDateService settleAccountDateService) {
		this.settleAccountDateService = settleAccountDateService;
	}
	
	@Action("editSettleAccountDate")
	public String editSettleAccountDate(){
		this.settleAccountDate=this.getSettleAccountDateService().getSettleAccountDate(serCode);
		return SUCCESS;
	}
	@Action(value="saveSettleAccountDate",results={
			@Result(name="success",type="redirect",location="editSettleAccountDate?serCode=${settleAccountDate.getType()}"),
			@Result(name="error",type="chain",location="editSettleAccountDate?serCode=${settleAccountDate.getType()}")
	})
	public String saveSettleAccountDate(){
		SettleAccountDate settle=this.getSettleAccountDateService().getSettleAccountDate("ss01");
		if (settle==null) {
			settle=new SettleAccountDate();
			settle.setType("ss01");
			settle.setDay(settleAccountDate.getDay());
			settle.setTime(settleAccountDate.getTime());
			settle.setModel(settleAccountDate.getModel());
			this.getSettleAccountDateService().save(settle);
		}
		else{
			this.getSettleAccountDateService().submit(settle);
		}
		settleAccountDate=settle;
		return SUCCESS;
	}
}	
